/*
 * Copyright (C) 2012 nutmotion <simonotmanuel@gmail.com>
 * Originally released under the tradeUplan project (wiki is at Expression project.wiki is undefined on line 5, column 85 in Templates/Licenses/license-gpl30.txt.)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.nutmotion.controller;

import com.nutmotion.model.bean.UserBean;
import com.nutmotion.model.jpa.Trade;
import com.nutmotion.service.TradeService;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author nutmotion <simonotmanuel@gmail.com>
 */
@ManagedBean
@RequestScoped
public class TestShowAllTradesController {
    @ManagedProperty(value="#{userBean}")
    private UserBean userBean;
    
    private List<Trade> allTradesForUser;
    
    /**
     * init method which job is to fetch all trades for the user
     */
    @PostConstruct
    private void init() {
    
        Trade tradeToMatch = Trade.build();
        
        tradeToMatch.setUser(getUserBean().getUser());
        
        setAllTradesForUser(new TradeService().match(tradeToMatch));
    }

    /**
     * @return the userBean
     */
    public UserBean getUserBean() {
        return userBean;
    }

    /**
     * @param userBean the userBean to set
     */
    public void setUserBean(UserBean userBean) {
        this.userBean = userBean;
    }

    /**
     * @return the allTradesForUser
     */
    public List<Trade> getAllTradesForUser() {
        return allTradesForUser;
    }

    /**
     * @param allTradesForUser the allTradesForUser to set
     */
    public void setAllTradesForUser(List<Trade> allTradesForUser) {
        this.allTradesForUser = allTradesForUser;
    }
    
}
